#include "Mote.h"

/*!
 * Creates a mote with id of id and no MoteInterface
 * \param[in]	id	The id of the new mote
 */
Mote::Mote(int id)
{
	this->reading = 0;
	this->recievedTime = 0;
	this->id = id;
}

Mote::~Mote()
{
	//
	// empty destructor for now
	//
}

/*!
 * Sets the LEDs of the mote. (To be implemented in the future.
 * \param LEDs		The LEDs of the mote as a short. 
 * <br>	1 for LED 0.
 * <br>	2 for LED 1.
 * <br> 4 for LED 2.
 * <br>For example, 7 is all on, and 0 is all off. 
 * \return	If the packet was successfully queued to be transfered to the
 * GameHub to be relayed to the mote. Will fail if the mote does
 * not exist, the serial write buffer is full, or there is no valid
 * MoteInterface set.
*/
bool Mote::setLEDs(short LEDs){
	//to be implemented in the future
}

/*!
 * Gets the expected value of the LEDs. (To be implemented in the future.
 * \return	The expected value of the LEDs as a byte.
 * <br>	1 for LED 0.
 * <br>	2 for LED 1.
 * <br> 4 for LED 2.
 * <br>For example, 7 is all on, and 0 is all off. 
 */
short Mote::getLEDs(){
	//to be implemented in the future
}

/*!
 * Sets a light reading for the mote
 * \param[in] reading	The new value of light reading
 */
void Mote::SetReading(READING_T reading)
{
	this->reading = reading;
	time(&(this->recievedTime));
}

/*!
 * Gets the last reading of the mote
 * \return the last reading of the mote
 */
READING_T Mote::Reading() const
{
	return reading;
}

/*!
 * Sets an arbitrary value associated with this mote
 */
void Mote::SetTag(TAG_T tag)
{
	this->tag = tag;
}

/*!
 * \return returns the tag value associated with this mote
 */
TAG_T Mote::GetTag()
{
	return tag;
}

/*!
 * Gets the received time of last reading
 * \return the recieved time of last reading
 */
TIMING_T Mote::RecievedTime() const{
	return recievedTime;	
}

/*!
 * Returns how old is the current reading
 * \return the elapsed since last recieved reading in seconds
 */
int Mote::SecondsSinceRecievedTime() const{
	TIMING_T c;
	time(&c);
	return c - this->RecievedTime();	
}

/*!
 * Defines the behaviour of outputing a Mote class to an output stream
 * \param[in]	out	The output stream (usually cout)
 * @param[in]	m	The Mote class variable
 * @return	A print out of Motes in Mote c
 */
ostream& operator<<(ostream& out, const Mote& m){
	out << m.GetId() << ":" << m.Reading() << ":" << m.SecondsSinceRecievedTime();
	return out;
}
